<?php

namespace StudyBuddy\Modules\Tumblr;

/**
 * Abstract class represents a post to
 * be submitted to Tumblr Write API
 *
 * A concrete class will represent Blog post, Photo, Link, Video or Audio
 *
 */
abstract class TumblrContent {

    protected $state = 'published';
    protected $private = 0;
    protected $id = null;

    public function getID() {
        return $this->id;
    }

    public function setID($id) {
        if (!is_numeric($id)) {
            throw new \InvalidArgumentException('$id must be numeric. Was: ' . $id);
        }

        $this->id = (int) $id;
    }

    /**
     * Get the type of content
     * sub-class must implement this
     *
     * @return string
     */
    abstract public function getType();

    /**
     *
     * Enter description here ...
     */
    public function getGenerator() {
        return 'StudyBuddy Tumblr API Client';
    }

    /**
     *
     * Getter for $this->state
     * @return string default is 'published'
     */
    public function getState() {
        return $this->state;
    }

    /**
     * Set content to 'private'
     * @return object $this
     */
    public function setPrivate() {
        $this->private = 1;

        return $this;
    }

    /**
     * Set this content as public
     *
     * @return object $this
     */
    public function setPublic() {
        $this->private = 0;

        return $this;
    }

    /**
     * Getter for $this->private
     *
     * @return int 0 means not private 1 means private
     *
     */
    public function getPrivate() {
        return $this->private;
    }

    /**
     * Set the state of post
     *
     *
     * @param string $state must be one of these strings:
     * 'published',
     * 	'submission',
     * 	'draft',
     * 	'queue',
     * 	'publish-on'
     *
     * @throws \InvalidArgumentException
     *
     * @return object $this
     */
    public function setState($state) {
        if (!is_string($state)) {
            throw new \InvalidArgumentException('$state must be a string. Was: ' . gettype($state));
        }

        $aAllowed = array(
            'published',
            'submission',
            'draft',
            'queue',
            'publish-on');

        if (!in_array($state, $aAllowed)) {
            throw new \InvalidArgumentException('value of $state must be one of these strings: ' . implode(',', $aAllowed) .
                    ' Was: ' . $state);
        }

        $this->state = (string) $state;

        return $this;
    }

}
